﻿using EmoneyWeiXinEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using EmoneyWeiXinCommon;

namespace EmoneyWeiXinDAL
{
    public class PanHouTJGDAL
    {
        public int Insert(PanHouTJGEntity info)
        {
            string sql = "INSERT INTO PanHouTJG VALUES(@stockName,@stockCode,@statu,GETDATE())";
            SqlParameter[] paras = 
            {
              new SqlParameter("@stockName",info.stockName),
              new SqlParameter("@stockCode",info.stockCode),
              new SqlParameter("@statu",info.statu)
            };
            return SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);
        }

        public int SetStartUsing(int id)
        {
            string sql = "UPDATE PanHouTJG SET @statu=1 WHERE ID=@ID";
            SqlParameter[] paras = 
            {
              new SqlParameter("@ID",id)
            };
            return SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);
        }

        public int Delete(int id)
        {
            string sql = "DELETE PanHouTJG WHERE ID=@ID";
            SqlParameter[] paras = 
            {
              new SqlParameter("@ID",id)
            };
            return SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.Text, sql, paras);
        }

        public PanHouTJGEntity GetLastSet()
        {
            string sql = "SELECT top 1* FROM PanHouTJG order by updateTime desc";
            return SQLHelper.GetDataByColumns<PanHouTJGEntity>(Config.EmoneyWeiXin, sql, null);
        }

        public List<PanHouTJGEntity> GetListByPage(int page)
        {
            string sql = @"SELECT TOP 30 [ID]
                         ,[stockName]
                         ,[stockCode]
                         ,[statu]
                         ,[updateTime]
                          FROM [PanHouTJG] order by updateTime desc";
            return SQLHelper.GetDataByColumnsLst<PanHouTJGEntity>(Config.EmoneyWeiXin, sql, null);
        }
    }
}
